package com.ruoyi.web.controller.myplan.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AwMyPlan;
import com.ruoyi.system.service.IAwMyPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 我的计划Controller
 *
 * @author anxinr
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/system/plan")
public class AwMyPlanController extends BaseController
{
    @Autowired
    private IAwMyPlanService awMyPlanService;

    /**
     * 查询我的计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwMyPlan awMyPlan)
    {
        startPage();
        List<AwMyPlan> list = awMyPlanService.selectAwMyPlanList(awMyPlan);
        return getDataTable(list);
    }

    /**
     * 导出我的计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:export')")
    @Log(title = "我的计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AwMyPlan awMyPlan)
    {
        List<AwMyPlan> list = awMyPlanService.selectAwMyPlanList(awMyPlan);
        ExcelUtil<AwMyPlan> util = new ExcelUtil<AwMyPlan>(AwMyPlan.class);
        util.exportExcel(response, list, "我的计划数据");
    }

    /**
     * 获取我的计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(awMyPlanService.selectAwMyPlanById(id));
    }

    /**
     * 新增我的计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:add')")
    @Log(title = "我的计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwMyPlan awMyPlan)
    {
        return toAjax(awMyPlanService.insertAwMyPlan(awMyPlan));
    }

    /**
     * 修改我的计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:edit')")
    @Log(title = "我的计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwMyPlan awMyPlan)
    {
        return toAjax(awMyPlanService.updateAwMyPlan(awMyPlan));
    }

    /**
     * 删除我的计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:remove')")
    @Log(title = "我的计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(awMyPlanService.deleteAwMyPlanByIds(ids));
    }
}
